package reflect;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;

public class ReflectDemo10 {
    public static void main(String[] args) throws Exception{
        Class cls = Class.forName("reflect.Person");
        if (cls.isAnnotationPresent(AutoRunClass.class)){

            Method method = cls.getDeclaredMethod("watchTV");
            if (method.isAnnotationPresent(AutoRunMethod.class)){
                /*
                    所有反射对象都支持方法:
                    Annotation getAnnotation(Class cls)
                    获取cls类对象表示的注解
                 */
                //返回当前method对象表示的方法"watchTV"上的注解@AutoRunMethod
                AutoRunMethod arm = method.getAnnotation(AutoRunMethod.class);
                int value = arm.value();
                System.out.println("参数值"+value);
            }

        }
    }
}
